//
//  GMChangePasswordDataController.m
//  GuardMan
//
//  Created by steven on 2016/12/30.
//  Copyright © 2016年 steven. All rights reserved.
//

#import "GMChangePasswordDataController.h"

@implementation GMChangePasswordDataController

- (void)changePasswordWithParams:(NSDictionary *)params callback:(GMCompletionCallback)callback {
    __weak typeof(self)weakSelf = self;
    [self requestWithType:POST url:ACTION_RESETPWD params:params success:^(id object) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.response = object;
        callback(nil);
    } failure:^(NSInteger statusCode, NSString *message) {
        NSString *errorString = nil;

        switch (statusCode) {
            case 404:
                errorString = @"用户不存在";
                break;
            case 406:
                errorString = @"无效请求值";
                break;
            case SERVER_NETWORK_OFF:
                errorString = @"服务器错误";
                break;
            case USER_NETWORK_OFF:
                errorString = @"请检查手机网络";
                break;
            default:
                errorString = UNKOWN_ERROR;
                break;
        }
        callback(message ? message : errorString);
    }];
}

- (void)changePasswordWhenForgotWithParams:(NSDictionary *)params callback:(GMCompletionCallback)callback {
    __weak typeof(self)weakSelf = self;
    [self requestWithType:POST url:ACTION_FORGETPWD params:params success:^(id object) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.response = object;
        callback(nil);
    } failure:^(NSInteger statusCode, NSString *message) {
        NSString *errorString = nil;
        switch (statusCode) {
            case 404:
                errorString = @"用户不存在";
                break;
            case 406:
                errorString = @"无效请求值";
                break;
            case SERVER_NETWORK_OFF:
                errorString = @"服务器错误";
                break;
            case USER_NETWORK_OFF:
                errorString = @"请检查手机网络";
                break;
            default:
                errorString = UNKOWN_ERROR;
                break;
        }
        callback(message ? message : errorString);
    }];
}
@end
